from lib.webui import *
import pytest


GSTORE = {}
def setup_module():
    wd = open_browser()
    GSTORE['wd'] = wd

def teardown_module():
    wd = GSTORE['wd']
    wd.quit()

@pytest.mark.冒烟
class Test_login1_5:

    @pytest.mark.parametrize('username,password,expect',
                             [
                                (None,'88888888','请输入用户名'),
                                ('byhy',None,'请输入密码'),
                                ('byh','88888888','登录失败 : 用户名或者密码错误'),
                                ('byhy','888888','登录失败 : 用户名或者密码错误'),
                                ('byhy','8888888888','登录失败 : 用户名或者密码错误')
                             ]
                            )

    def test_a(self,username,password,expect):
        wd = GSTORE['wd']
        username_input = wd.find_element(By.CSS_SELECTOR,'#username')
        password_input = wd.find_element(By.CSS_SELECTOR,'#password')
        username_input.clear()
        password_input.clear()
        if username:
            username_input.send_keys(username)
        if password:
            password_input.send_keys(password)
        
        wd.find_element(By.CSS_SELECTOR,'button').click()
        time.sleep(0.5)
        info = wd.switch_to.alert.text
            
        wd.switch_to.alert.accept()
        assert info == expect
    